package com.board.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.board.dao.OrderDetailMapper;
import com.board.entity.OrderDetail;
import com.board.exception.OrderDetailException;
import com.board.service.OrderDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 膳食系统-订单详情表 服务实现类
 * </p>
 *
 * @author 小叶
 * @since 2024年04月04日
 */
@Service
public class OrderDetailServiceImpl extends ServiceImpl<OrderDetailMapper, OrderDetail> implements OrderDetailService {
    @Autowired
    private OrderDetailMapper orderDetailMapper;
    @Override
    public OrderDetail findOrderDetailById(Integer orderDetailId) {
        OrderDetail orderDetail = orderDetailMapper.selectById(orderDetailId);
        if (orderDetail==null) throw new OrderDetailException(500,"不存在该订单详情");
        return orderDetail;
    }

    @Override
    public List<OrderDetail> findOrderDetailByOrderNum(String orderNum) {
        //判断订单编号是否存在
        QueryWrapper<OrderDetail> wrapper = new QueryWrapper<>();
        wrapper.eq("order_num",orderNum);
        List<OrderDetail> details = orderDetailMapper.selectList(wrapper);
        if (details.size() == 0) {
            throw new OrderDetailException(500,"不存在该订单详情");
        }
        return details;
    }
}
